package org.example.queueadmin.dlq;

import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Base64;
import java.util.List;

@RestController
@RequestMapping("/api/dlq")
@RequiredArgsConstructor
public class DeadLetterController {
  private final DeadLetterService dlq;

  @GetMapping(value = "/{taskId}", produces = MediaType.APPLICATION_JSON_VALUE)
  public List<String> list(@PathVariable Long taskId, @RequestParam(defaultValue = "0") long start, @RequestParam(defaultValue = "20") long count) {
    return dlq.rangeBase64(taskId, start, count);
  }

  @DeleteMapping("/{taskId}")
  public ResponseEntity<Void> clear(@PathVariable Long taskId) {
    dlq.clear(taskId);
    return ResponseEntity.ok().build();
  }
}

